using UnityEngine;
using System.Collections;

public class ParentBlock : MonoBehaviour {

	private Vector2 lastPosition;

	// Use this for initialization
	void Start () {
	
	}

	void FixedUpdate()
	{
 		Vector3 velocity = new Vector3(transform.position.x - lastPosition.x, transform.position.y - lastPosition.y, 0);
		float distance =  velocity.magnitude;
		velocity.Normalize();
		RaycastHit hit;
		if(rigidbody.SweepTest(velocity, out hit, distance))
		{
			if(hit.collider.GetComponent<ParentBlock>())
			{
				Component iTweenCompo = GetComponent<iTween>();
				if(iTweenCompo != null) {
					Destroy(iTweenCompo);
					//transform.position = lastPosition;
					//iTween.ShakePosition(gameObject, Vector3.down, 0.2f);
				}
			}
		}
		lastPosition = transform.position;
	}

	
	// Update is called once per frame
	void Update () {

	}
}
